package chart;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

// 散点图(点不同)
public class ScatterChartDemo extends Application {
	private Pane root = new Pane();
	private CategoryAxis x = new CategoryAxis();
	private NumberAxis y = new NumberAxis(0, 100, 10);
	private ScatterChart<String, Number> sc = new ScatterChart<>(x, y);
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
		sc.setStyle("-fx-background-color: lightyellow");
		sc.setPrefSize(400, 400);
		x.setLabel("食物");
		y.setLabel("价格");
		
		XYChart.Data<String, Number> data1 = new XYChart.Data<String, Number>("鸡肉", 20);	
		XYChart.Data<String, Number> data2 = new XYChart.Data<String, Number>("鸭肉", 18);
		XYChart.Data<String, Number> data3 = new XYChart.Data<String, Number>("牛肉", 50);
		XYChart.Data<String, Number> data4 = new XYChart.Data<String, Number>("猪肉", 30);
		XYChart.Data<String, Number> data5 = new XYChart.Data<String, Number>("白菜", 2);
		XYChart.Data<String, Number> data6 = new XYChart.Data<String, Number>("茄子", 4);
		
		XYChart.Series<String, Number> xy1 = new XYChart.Series<>();	// 每一种的点不同
		xy1.getData().add(data1);
		
		XYChart.Series<String, Number> xy2 = new XYChart.Series<>();
		xy2.getData().add(data2);
		
		XYChart.Series<String, Number> xy3 = new XYChart.Series<>();
		xy3.getData().add(data3);
		
		XYChart.Series<String, Number> xy4 = new XYChart.Series<>();
		xy4.getData().add(data4);
		
		XYChart.Series<String, Number> xy5 = new XYChart.Series<>();
		xy5.getData().add(data5);
		
		XYChart.Series<String, Number> xy6 = new XYChart.Series<>();
		xy6.getData().add(data6);
		sc.getData().add(xy1);
		sc.getData().add(xy2);
		sc.getData().add(xy3);
		sc.getData().add(xy4);
		sc.getData().add(xy5);
		sc.getData().add(xy6);
		root.getChildren().add(sc);
		
		Scene scene = new Scene(root, 400, 400);
		stage.setScene(scene);
		stage.show();
	}

}
